package com.captjack.mybatiesplus.configuration;

import com.baomidou.mybatisplus.plugins.PaginationInterceptor;
import com.zaxxer.hikari.HikariDataSource;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/**
 * Description description.....
 *
 * @author Jack Sparrow
 * @version 1.0.0
 * @date 2018/6/13 23:11
 * package com.captjack.mybatiesplus.configuration
 */
@Configuration
@MapperScan(basePackages = "com.captjack.mybatiesplus.mapper")
@EnableTransactionManagement
public class MybatisPlusConfiguration {

    /**
     * @return 数据源
     */
    @Bean
    @ConfigurationProperties(prefix = "spring.datasource.hikari")
    DataSource mysqlDataSource() {
        return new HikariDataSource();
    }

    /**
     * 分页插件，自动识别数据库类型
     */
    @Bean
    PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

}
